<template>
  <div class="layout-pd">
    <zh-card title="查询条件" v-if="pageData.showType">
      <zh-form :model="pageData.queryParams" ref="queryFormRef" label-width="160px" :span="8">
        <zh-form-select
            prop="consumerAppId"
            :lazy="true"
            label="请求方应用"
            v-model="pageData.queryParams.consumerAppId"
            :fieldNames="{ label: 'appName', value: 'appId' }"
            funcCode="application0012"
            searchField="appName"
        ></zh-form-select>
        <zh-form-select
            prop="retCode"
            label="调用状态"
            :options="flagData"
            v-model="pageData.queryParams.retCode"
        ></zh-form-select>
        <template v-if="pageData.advanced">
        </template>
        <zh-form-query v-model="pageData.advanced" :tableRef="queryTable" :formRef="queryFormRef">

        </zh-form-query>
      </zh-form>
    </zh-card>
    <zh-table title="" ref="queryTable" size="mini" funcCode="APILOG0001" :columns="pageData.tableColumns" highlight-current-row>
      <template #flag_default="{ row }">
        <zh-badge :status="statusMap[row.retCode].status" :text="statusMap[row.retCode].text" />
      </template>

      <template #operate="{ row }">
        <zh-button v-func:APILOG0002 link @click="showdetail(row, true)" style="color: green">查看</zh-button>
      </template>
    </zh-table>

    <zh-dialog style="width: 80%" :title="pageData.title" v-model="pageData.detailVisible">
      <apiLogForm
          ref="menuRef"
          :disabled="pageData.editFlag"
          @canner="canner"
          @refreshTable="refreshTable"
          :logId="pageData.selectRow.logId"
      ></apiLogForm>
      <template #footer>
				<span class="dialog-footer">
					<zh-button @click="pageData.detailVisible = false">关闭</zh-button>
					<zh-button
              type="primary"
              :loading="pageData.saveLoading"
              :disabled="pageData.saveLoading"
              v-model:btnLoding="pageData.saveLoading"
              @click="save"
          >
						保存
					</zh-button>
				</span>
      </template>
    </zh-dialog>
  </div>
</template>
<script lang="ts" setup name="apiLogIndex">
import { ElMessageBox, ElMessage } from 'element-plus';
import apiLogForm from './component/apiLogForm.vue';

// ------------------接收传入参数(组件)-------------------

// ------------------钩子函数----------------------------
// 初始化
onMounted(() => {
  init();
});

// ------------------定义子组件--------------------------
const queryTable = ref();
const queryFormRef = ref();
const menuRef = ref();

const statusMap = {
  1: {
    status: 'processing',
    text: '成功',
  },
  0: {
    status: 'error',
    text: '失败',
  },
};

const flagData = [{dictKey:'1',dictValue:'成功'},{dictKey:'0',dictValue:'失败'}];


// ------------------变量区------------------------------
const pageData = reactive({
  advanced: false,

  tableColumns: [
    {
      type: 'seq',
      minWidth: 60,
      fixed: 'left',
      align: 'center',
      title: '序号',
    },
    {
      field: 'logId',
      title: '主键',
      visible: false,
      align: 'center',
      minWidth: 80,
    },
    {
      field: 'retCode',
      title: '交易结果状态',
      visible: true,
      align: 'center',
      minWidth: 150,
      slots: {
        // 使用插槽模板渲染
        default: 'flag_default',
      },
    },
    {
      field: 'message',
      title: '交易结果 信息',
      visible: true,
      align: 'center',
      minWidth: 150,
    },
    {
      field: 'interfaceCode',
      title: '接口编号',
      visible: true,
      align: 'center',
      minWidth: 150,
    },
    {
      field: 'title',
      title: '接口名称',
      visible: true,
      align: 'center',
      minWidth: 150,
    },
    {
      field: 'reqTime',
      title: '请求时间',
      visible: true,
      align: 'center',
      minWidth: 150,
    },
    {
      field: 'resTime',
      title: '返回时间',
      visible: true,
      align: 'center',
      minWidth: 150,
    },
    {
      field: 'takingTime',
      title: '总耗时 单位秒',
      visible: true,
      align: 'center',
      minWidth: 150,
    },
    {
      field: 'convertReqTime',
      title: '接口调用转换耗时 单位秒',
      visible: true,
      align: 'center',
      minWidth: 150,
    },
    {
      field: 'convertResTime',
      title: '接口返回转换耗时 单位秒',
      visible: true,
      align: 'center',
      minWidth: 150,
    },
    {
      field: 'producerTakingTime',
      title: '调用第三方服务耗时  单位秒',
      visible: true,
      align: 'center',
      minWidth: 150,
    },
    {
      field: 'reqBody',
      title: '请求报文',
      visible: true,
      align: 'center',
      minWidth: 150,
    },
    {
      field: 'resBody',
      title: '返回报文',
      visible: true,
      align: 'center',
      minWidth: 150,
    },
    {
      field: 'reqConvertBody',
      title: '请求报文(转换后)',
      visible: true,
      align: 'center',
      minWidth: 150,
    },
    {
      field: 'resConvertBody',
      title: '返回报文(转换后)',
      visible: true,
      align: 'center',
      minWidth: 150,
    },
    {
      field: 'consumerAppId',
      title: '调用方 应用',
      visible: true,
      align: 'center',
      minWidth: 150,
    },
    {
      field: 'consumerClientId',
      title: '应用id',
      visible: true,
      align: 'center',
      minWidth: 150,
    },
    {
      field: 'consumerAppName',
      title: '调用方 应用系统名称',
      visible: true,
      align: 'center',
      minWidth: 150,
    },
    {
      field: 'consumerId',
      title: '消费者主键',
      visible: true,
      align: 'center',
      minWidth: 150,
    },
    {
      field: 'producerAppId',
      title: '所属应用 服务方',
      visible: true,
      align: 'center',
      minWidth: 150,
    },
    {
      field: 'producerAppName',
      title: '应用系统名称 服务方',
      visible: true,
      align: 'center',
      minWidth: 150,
    },
    {
      field: 'producerPath',
      title: '转发地址',
      visible: true,
      align: 'center',
      minWidth: 150,
    },
    {
      field: 'ym',
      title: '年月',
      visible: true,
      align: 'center',
      minWidth: 150,
    },
    {
      field: 'reqIp',
      title: '请求ip',
      visible: true,
      align: 'center',
      minWidth: 150,
    },
    {
      field: 'areaCode',
      title: '行政区划',
      visible: true,
      align: 'center',
      minWidth: 150,
    },
    {
      field: 'operate',
      title: '操作',
      fixed: 'right',
      align: 'center',
      minWidth: 210,
      slots: {
        // 使用插槽模板渲染
        default: 'operate',
      },
    },
  ],
  queryParams: {} as any,
  dictData: {} as any,
  title: '',
  detailVisible: false,
  editFlag: false,
  selectRow: {} as any,
  saveLoading: false,
  showType: true,
  campusParam: {} as any,
});
// ------------------方法区------------------------------
const init = () => {
  getDict();
  refreshTable();
};
// 查询数据字典信息
const getDict = () => {
  const params = {} as any;
  params.dictFields = '';
  $api.common.getBatchDict.post(params).then((res) => {
    pageData.dictData = res.result;
  });
};

//使用子组件方法，关闭弹窗
const canner = (e: any) => {
  pageData.detailVisible = e;
};

const showAdd = () => {
  pageData.title = '新增';
  pageData.detailVisible = true;
  pageData.editFlag = false;
  pageData.selectRow = {};
};

const showdetail = (row, flag) => {
  if (!flag) {
    pageData.title = '信息修改';
  } else {
    pageData.title = '查看详情';
  }
  pageData.selectRow = row;
  pageData.editFlag = flag;
  pageData.detailVisible = true;
};
//保存
const save = () => {
  menuRef.value.saveBase();
};

//刷新
const refreshTable = () => {
  queryTable.value.refresh(pageData.queryParams);
};
//删除
const deleteData = (row) => {
  ElMessageBox.confirm('是否确认删除？').then(() => {
    let params = {} as any;
    params.logId = row.logId;
    $api.common.send.post('APILOG0006', params).then(() => {
      ElMessage.success('删除成功');
      refreshTable();
    });
  });
};

</script>
<style lang="scss" scoped></style>
